#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

from twisted.internet.protocol import Protocol, ClientFactory 
from twisted.internet import reactor

class QuickDisconnectProtocol(Protocol):
    def connectionMade(self):
        print "Connected to %s." % self.transport.getPeer().host
        self.transport.loseConnection()
        
class BasicClientFactory(ClientFactory):
    protocol = QuickDisconnectProtocol
    
    def clientConnectionLost(self, connector, reason):
        print "Lost Connection: %s" % reason.getErrorMessage()
        reactor.stop()
        
    def clientConnectionFailed(self, connector, reason):
        print "Connection failed: %s" % reason.getErrorMessage()
        reactor.stop()
        
reactor.connectTCP('www.google.com', 80, BasicClientFactory())
reactor.run()